from time import sleep
from threading import Thread,Lock,current_thread

class Account():
	def __init__(self):
		self._lock = Lock()
		self._balance = 0

	def deposit(self,money):
		self._lock.acquire()

		try:
			# new_balance = self._balance + money
			# sleep(0.01)
			# self._balance = new_balance
			self._balance += money
			sleep(0.01)
		finally:
			self._lock.release()

	@property
	def balance(self):
		return self._balance
	


class AddMoney(Thread):
	def __init__(self, account, money):
		super().__init__()
		self._account = account
		self._money = money

	def run(self):
		self._account.deposit(self._money)


if __name__ == '__main__':
	account = Account()
	threads = []
	for _ in range(100):
		a = AddMoney(account,1)
		threads.append(a)
		a.start()

	for thread in threads:
		thread.join()

	print(account.balance)


